package bankofficegrepper

import groovy.xml.MarkupBuilder

/**
 * Created by IntelliJ IDEA.
 * User: janexie
 * Date: 2010-12-18
 * Time: 20:05:57
 * To change this template use File | Settings | File Templates.
 */
class BankInfoWriter {
  def fileName

  BankInfoWriter(fileName){
    this.fileName = fileName
  }
  def writeTo(List<BankInfo> infoList) {
    println infoList.get(0).getAddress()
    def writer = new StringWriter()
    def xml = new MarkupBuilder(writer);
    BankInfo bankinfo = new BankInfo();
    xml.bankinfos {
      infoList.each {
        bankinfo = (BankInfo) it;
        xml.bankinfo {
          name(bankinfo.getName())
          type(bankinfo.getType())
          address(bankinfo.getAddress())
          city(bankinfo.getCity())
          province(bankinfo.getProvince())
          serviceTime(bankinfo.getServiceTime())
          telephoneNo(bankinfo.getTelephoneNo())
        }
      }
    }

    def file = new File(fileName)
    file.write(writer.toString())
    writer.toString()
  }
}

